<%@ page language="java"  contentType="text/html;charset=UTF-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>资源管理-新增/更新资源</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script language="javascript" type="text/javascript">
function closeCurrentWindow(result) {
	var winId='${winId}';
	var closeWin=Ext.WindowMgr.get(winId);
	if(closeWin==null) {
		closeWin=parent.Ext.WindowMgr.get(winId);
	}
	if(closeWin==null) {
		window.returnValue=result;
		window.close();
	}else {
		closeWin.returnValue=result;
		closeWin.close();
	}
}

var ynStore = new Ext.data.ArrayStore({
    fields: ['value','text'],
    data: [[true,'是'],[false,'否']]
});

Ext.onReady(function() {

	var formPanel = new Ext.form.FormPanel({
		bodyStyle: 'padding: 10 10 10 10;',
		layout: 'form',
		autoWidth: true,
		autoScroll: true,
		labelAlign: 'right',
		labelWidth: 85,
		items: [{
			border: false,
			layout: 'column',
			items: [{
				// 第1列
				columnWidth : .33,
				border: false,
				layout: 'form',
				defaults: {
					anchor: '100%',
					msgTarget: 'qtip',
					validateOnBlur: false
				},
				items: [{
					name: 'id',
					xtype: 'hidden'
				},{
					xtype: 'hidden',
					name: 'parentId',
					value: '${parentId}'
				},{
					xtype: 'textfield',
					fieldLabel: '上级分类名称',
					name: 'parentName',
					disabled: true,
					value: '${PARENT_NAME}'
				},{
					xtype: 'combo',
					fieldLabel: '是否叶子节点',
					allowBlank: false,
					name: 'isLeaf',
					hiddenName: 'isLeaf',
					mode: 'local',
					triggerAction: 'all',
					valueField: 'value',
					displayField: 'text',
					editable: false,
				    store: ynStore,
				    value: false,
				    readOnly: ${IS_LEAF_READ_ONLY}
				},{
					xtype: 'textfield',
					fieldLabel: 'URL',
					allowBlank: false,
					name: 'url',
					maxLength: 128,
					value: '/'
				}]
			},{
				// 第2列
				columnWidth : .33,
				border: false,
				layout: 'form',
				defaults: {
					anchor: '100%',
					msgTarget: 'qtip',
					validateOnBlur: false
				},
				items: [{
					xtype: 'textfield',
					fieldLabel: '资源名称',
					allowBlank: false,
					name: 'name',  
					maxLength: 64
				},{
					xtype: 'combo',
					fieldLabel: '是否登录可用',
					allowBlank: false,
					name: 'needLogin',
					hiddenName: 'needLogin',
					mode: 'local',
					triggerAction: 'all',
					valueField: 'value',
					displayField: 'text',
					editable: false,
				    store: ynStore,
				    value: true
				},{
					xtype: 'textfield',
					fieldLabel: '事件名',
					allowBlank: false,
					name: 'actionName',
					maxLength: 16,
					value: 'action'
				}]
			},{
				// 第3列
				columnWidth : .34,
				border: false,
				layout: 'form',
				defaults: {
					anchor: '100%',
					msgTarget: 'qtip',
					validateOnBlur: false
				},
				items: [{
					xtype: 'combo',
					fieldLabel: '是否可见',
					allowBlank: false,
					name: 'isVisible',
					hiddenName: 'isVisible',
					mode: 'local',
					triggerAction: 'all',
					valueField: 'value',
					displayField: 'text',
					editable: false,
				    store: ynStore,
				    value: true
				},{
					xtype: 'combo',
					fieldLabel: '是否公共资源',
					allowBlank: false,
					name: 'isPublic',
					hiddenName: 'isPublic',
					mode: 'local',
					triggerAction: 'all',
					valueField: 'value',
					displayField: 'text',
					editable: false,
				    store: ynStore,
				    value: false
				},{
					xtype: 'textfield',
					fieldLabel: '附加参数',
					allowBlank: true,
					name: 'paraUrl',
					maxLength: 128
				}]
			}]
		}${operationIdsHTML},{
           	fieldLabel: '备注',
           	xtype: 'textarea',
			name: 'memo',
			anchor: '100%'
		}],
		listeners: {
			afterRender: function(thiz){
				var id='${id}';
				if(!Ext.isEmpty(id)&&id!='null') {
					var url='${ctx}/resource!getJSON.action';
					var params={
							id: id
					};
					Common.loadForm(thiz,url,params);
				}
			}
		},
		bbar: [{
			text: '保存',
			iconCls: 'acceptBtn',
			handler: function() {
				if (!formPanel.form.isValid(false)) {
					return;
				}
				var action;
				var id='${id}';
				var isUpdate=!Ext.isEmpty(id)&&id!='null';
				if(isUpdate) {
					action='updateJSON';
				}else {
					action='insertJSON';
				}
				formPanel.form.submit({
					method: 'post',
					waitTitle: ' ',
					waitMsg: '正在提交数据, 请稍后... ...',
					url: '${ctx}/resource!'+action+'.action',
					params: {},
					failure: function(form,action) {
						Ext.Msg.hide();
		        		Common.parseFailureResponse(action.response);
					},
					success: function(form,action) {
						var result=action.result;
						Common.parse(result,function(buttonId) {
							Ext.Msg.hide();
							if(result.pass||buttonId=='yes') {
								closeCurrentWindow(result.attributes);
							}
						});
					}
				});
			}
		},'-',{
			iconCls: 'delete2Btn',
			text: '取消',
			handler: function() {
				closeCurrentWindow(false);
			}
		}]
	});

	var viewport = new Ext.Viewport({
		layout: 'fit',
		border: false,
		items: [formPanel]
	});
	
});
</script>
</head>

<body>
</body>
</html>
